import os
# from tqdm import tqdm
'''参考此文档https://blog.csdn.net/zhengshiougea/article/details/103062720'''
import multiprocessing
def update_lists():
    '''升级函数'''
    #在控制台中执行命令,并有返回值,存入到变量r中
    r = os.popen("C:/Users/x6985/.conda/envs/pt2/python.exe -m pip list --outdate")
    #读取r并自动换行
    r = r.read().splitlines()
    update_list = []
    if len(r)>2:
        for update in r[2:]:
            outdated_pkg = update.split(" ",1)[0]
            update_list.append(outdated_pkg)
        print(update_list)
    return update_list

def run(pkg):
    #执行这个指令,并有返回值
    cmds = f'C:/Users/x6985/.conda/envs/pt2/python.exe -m pip install --upgrade {pkg}'
    tmp = os.popen(cmds)
    print(f"{pkg}升级完成")
    # #创建进程池
def main():
    updates_lists = update_lists()
    print(updates_lists)
    pool = multiprocessing.Pool()   
    pool.map_async(run,updates_lists)
    print("进程结束")
    pool.close()
    pool.join()
    print('已完成')

if __name__ == "__main__":
    main()
